"""meiduo_mall URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url,include
from django.contrib import admin
from rest_framework import routers


from apps.books.views import HeroViewSet
from . import views

urlpatterns = [
    #查询所有图书
    # url(r'^books/$', views.BooksView.as_view()),
    #查询所有的英雄
    # url(r'^heros/$', views.HerosView.as_view()),
    # #查询单个英雄
    # url(r'^heros/(?P<pk>\d+)/$', views.HeroView.as_view()),

    # url(r'^heros/$', views.HerosAPIView.as_view()),
    # #查询单个英雄
    # url(r'^heros/(?P<pk>\d+)/$', views.HeroAPIView.as_view()),

    # url(r'^heros/$', views.HerosGenericView.as_view()),
    # # 查询单个英雄
    # url(r'^heros/(?P<pk>\d+)/$', views.HeroGenericView.as_view()),

    # url(r'^heros/$', views.HerosGenericAPIView.as_view()),
    # # 查询单个英雄
    # url(r'^heros/(?P<pk>\d+)/$', views.HeroGenericAPIView.as_view()),

    #Viewsets  将里面的合并
    url(r'^heros/$', views.HeroViewSet.as_view({'get':'list','post':'create'})),
    # 查询单个英雄
    url(r'^heros/(?P<pk>\d+)/$', views.HeroViewSet.as_view({'put':'update','get':'retrieve','delete':'destroy'})),

]

# router = routers.SimpleRouter()
#DefaultRouter与SimpleRouter的区别是，
# DefaultRouter会多附带一个默认的API根视图
# 返回一个包含所有列表视图的超链接响应数据。
router = routers.DefaultRouter()
router.register(r'heros',HeroViewSet , base_name='heros')
urlpatterns += router.urls